package com.ruoyi.web.controller.water;

import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableSupport;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.control.domain.JingxiaHistory;
import com.ruoyi.control.service.IJingxiaHistoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 井下水文历史数据Controller
 * 
 * @author ruoyi
 * @date 2024-11-08
 */
@RestController
@RequestMapping("/control/jingxiaHistory")
public class JingxiaHistoryController extends BaseController
{
    @Autowired
    private IJingxiaHistoryService jingxiaHistoryService;

    /**
     * 查询井下水文历史数据列表
     */
    @PreAuthorize("@ss.hasPermi('control:jingxiaHistory:list')")
    @GetMapping("/list")
    public TableDataInfo list(JingxiaHistory jingxiaHistory)
    {
//        startPage();
//        List<JingxiaHistory> list = jingxiaHistoryService.selectJingxiaHistoryList(jingxiaHistory);
//        return getDataTable(list);
        List<JingxiaHistory> list = jingxiaHistoryService.selectJingxiaHistoryList(jingxiaHistory);
        TableDataInfo rspData = new TableDataInfo();
        Integer total = Math.toIntExact(list.size());
        rspData.setCode(200);
        rspData.setTotal(total);
        rspData.setMsg("查询成功");

        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        list = list.stream().skip((pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
        rspData.setRows(list);

        return rspData;
    }

    /**
     * 导出井下水文历史数据列表
     */
    @PreAuthorize("@ss.hasPermi('control:jingxiaHistory:export')")
    @Log(title = "井下水文历史数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JingxiaHistory jingxiaHistory)
    {
        List<JingxiaHistory> list = jingxiaHistoryService.selectJingxiaHistoryList(jingxiaHistory);
        ExcelUtil<JingxiaHistory> util = new ExcelUtil<JingxiaHistory>(JingxiaHistory.class);
        util.exportExcel(response, list, "井下水文历史数据数据");
    }

    /**
     * 获取井下水文历史数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('control:jingxiaHistory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(jingxiaHistoryService.selectJingxiaHistoryById(id));
    }

    /**
     * 新增井下水文历史数据
     */
    @PreAuthorize("@ss.hasPermi('control:jingxiaHistory:add')")
    @Log(title = "井下水文历史数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JingxiaHistory jingxiaHistory)
    {
        return toAjax(jingxiaHistoryService.insertJingxiaHistory(jingxiaHistory));
    }

    /**
     * 修改井下水文历史数据
     */
    @PreAuthorize("@ss.hasPermi('control:jingxiaHistory:edit')")
    @Log(title = "井下水文历史数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JingxiaHistory jingxiaHistory)
    {
        return toAjax(jingxiaHistoryService.updateJingxiaHistory(jingxiaHistory));
    }

    /**
     * 删除井下水文历史数据
     */
    @PreAuthorize("@ss.hasPermi('control:jingxiaHistory:remove')")
    @Log(title = "井下水文历史数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(jingxiaHistoryService.deleteJingxiaHistoryByIds(ids));
    }


    /**
     * 水文瞬时流量
     */
    @GetMapping("/getInstantFlow")
    public TableDataInfo getInstantFlow()
    {
        List<JingxiaHistory> list = jingxiaHistoryService.getInstantFlow();
        return getDataTable(list);
    }


    /**
     * 苍海水文瞬时流量
     */
    @GetMapping("/getChInstantFlow")
    public TableDataInfo getChInstantFlow()
    {
        List<JingxiaHistory> list = jingxiaHistoryService.getChInstantFlow();
        return getDataTable(list);
    }



}
